Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:04:38+00:00 2026-05-13T18:04:38+00:00

My main goal is to generate an XML file that can be downloaded. The

  • 0

My main goal is to generate an XML file that can be downloaded.

The below code succeeds in generating the file but the view (/Home/XmlView) can be accessed directly.

If I use the [Authorize] attribute on the XmlView() method then the file is created with the HTML of my default logon page.

How do get the authorization to work with the XmlView() method or do all of this more efficiently?

I am open to any any suggestions.

Thanks in advance.

using System;
using System.Net;
using System.Text;
using System.Web.Mvc;
using MvcProject.Core.Repositories;

namespace MvcProject.Core.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private readonly IEntryRepository _entryRepository;

        public HomeController(IEntryRepository entryRepository)
        {
            _entryRepository = entryRepository;
        }

        [HttpGet]
        [Authorize]
        public ActionResult Download()
        {
            var url = Url.Action("XmlView", "Home", null, "http");

            var webClient = new WebClient
                                {
                                    Encoding = Encoding.UTF8,
                                    UseDefaultCredentials = true
                                    //Credentials = CredentialCache.DefaultCredentials
                                };

            var fileStringContent = webClient.DownloadString(url);

            var fileByteContent = Response.ContentEncoding.GetBytes(fileStringContent);

            return File(fileByteContent, "application/xml",
                        string.Format("newfile{0}.xml", DateTime.Now.ToFileTime()));
        }

        //[Authorize]
        public ActionResult XmlView()
        {
            return View("XmlView", _entryRepository.GetAll());
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:04:38+00:00Added an answer on May 13, 2026 at 6:04 pm

    I didn’t intend to answer my own question, but I ended up making a form with a single input (a submit button) that posts to the following method:

    [HttpPost, Authorize]
    public ActionResult Download()
    {
        Response.ContentType = "application/vnd.xls";
        Response.AddHeader("content-disposition",
                           "attachment;filename=" +
                           string.Format("Registrants-{0}.xls", String.Format("{0:s}", DateTime.Now)));
    
        return View("XmlView", _entryRepository.GetAll());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application thats main goal is to play a specific video file.
How do i do that? Actually my main goal is to get which checkbox
If i have xsd file in the following directories src/main/resources/xsd src/main/resources/schema/common src/main/resources/schema/soap How can
I'm busy writing a servlet that generates HTML code. The goal is to create
I'm trying to generate a .jar containing a main() that would start Jetty. My
I'm using jaxb to generate java source code from an xsd file. I want
Current, I've got a stored procedure that has a main goal of doing a
The main goal of my issue is to put specific colors on Donut Change.
My main goal is to change the volume on one sound card based on
For homework, I need to build a small java application.The main goal is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.