Permission Control for file downloads (asp.net)

Source: Internet
Author: User
Tags iis log
asp.net| Control | Download the author to do a report of the site, the report is stored in Excel form in the server, you want to log on to the person or have permission to download Excel reports. However, the path to the file download cannot be hidden, so page control is useless. Recently in the study of IIS, suddenly enlightened.



First edit or modify the site's Web.config, add or modify the red area

<!--authentication

This section sets the authentication policy for the application. The possible patterns are "Windows",

"Forms", "Passport" and "None"



"None" does not perform authentication.

"Windows" IIS performs authentication based on the settings of the application

(Basic, concise, or integrated Windows). Anonymous access must be disabled in IIS.

Forms you provide users with a custom form for entering credentials (a Web page), and then

Verify their identities in your application. The user credential token is stored in the Cookie.

"Passport" authentication is performed through a centralized authentication service in Microsoft.

It provides individual logins and core profile services for member sites.

-->

<authentication mode= "Forms" >

<forms name= ". Aspxuserdemo "loginurl=" Login.aspx "protection=" All "timeout=" "path="/"><credentials passwordformat=" SHA1 " /></forms>

</authentication>





<!--authorization

This section sets the authorization policy for the application. You can allow or deny access to different users or roles

Application resources. Wildcard: "*" means any person, "?" means anonymity

(unauthenticated) user.

-->



<authorization>

<deny users= "?" />

<!--<allow users= "[Comma separated list of users]"

roles= "[comma-separated role list]"/>

<deny users= "[Comma separated list of users]"

roles= "[comma-separated role list]"/>

-->

</authorization>



And then write Login.aspx.

Join for Successful Login

Formsauthentication.setauthcookie (Uid,false);

FormsAuthentication.RedirectFromLoginPage (Uid,false);



Open IIS, find your site, point right, select attributes,-"Home directory-" configuration


Then select Add in "mappings",


Add as shown above.

All right, here we go. Now visit an XLS document under the main station Http://localhost/sms/1.xls, what do you see?


Oh, yes, you need to log in. When you enter the login information and log in you can download this file!




Yes, that's simple, if you add role, you can have more complex control.

Welcome to Exchange (maximon@sina.com Wuxi National tax Gu Huichun)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.