I want to url redired in asp.net using web.config - asp.net

I have one or more than one url like http://vfiresolution.in/pdf/p.pdf. And I want to redirect the above url to http://vfiresolution.in/page.aspx?id=1.
I am using the below given code. My code is working on local host. But If i publish my code on shared server code not working.
my code is
<configuration>
<location path="pdf/p.pdf">
<system.webServer>
<httpRedirect enabled="true" destination="http://vfiresolution.in/page.aspx?id=1" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>

http://www.iis.net/configreference/system.webserver/httpredirect
check the iis
(httpredirect)
Compatibility
The httpRedirect section of web.config is compatible with IIS 7 (w2k8) and IIS 7.5 (w2k8 r2).
Web.config files are deeply integrated with IIS 7.x.
The httpRedirect directives listed will apply to all files and directories (php, jpg, png, htm, etc), not just asp.net files.
While some web.config sections sometimes require that the containing directory is set as an application, this isn't one of them.
A simple web.config with a httpRedirect section may be placed in any directory, and the directory does NOT need to be set as an application.

Related

IIS Subsite with different web.config, Is it possible?

My IIS subsite take the web.config from the main site. How to avoid it?
I want my subsite just read its own web.config and works as independent site
This is how it looks in IIS:
img1
Yes, web.config contains the server configuration information related to each web application, there should be a web.config in the root folder of your web application.
If you want different web.config for subsite, you can place web.config file under your subsite of application.
<location path="." inheritInChildApplications="false">
<system.web> 
...
</system.web>
</location>

Web.config in subdirectory causing 500 internal server error

I have a working ASP.NET web application. I'm trying to enable SSL using Let's Encrypt and to do this my shared web host host (A2) adds a web.config in the .well-known/acme-challenge directory. (All this web.config does is to bind extensionless files to plain text).
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/plain" />
</staticContent>
</system.webServer>
</configuration>
The issue is the mere presence of a web.config in a subfolder seems to cause any request for resources from this folder to fail, returning a 500 error. I've even tried a completely empty web.config in this folder and that still causes 500 errors. My understanding is that ASP.NET should support additional web.configs in subfolders but I have no idea why it isn't working.
I have a web.config in my root folder with the proper binding for extensionless files but the A2 Let's Encrypt tool insists on adding its own into the subfolder. I do not have any attributes preventing overridding in this web.config.
I've searched extensively for how to fix this but most of the solutions I see require changing IIS configuration. As this is a shared web host, I have extremely limited control over IIS, so that is not a viable option.
Can you add this to your root web.config:
<customErrors mode="Off" />
... which will then result in some more error information included in the 500 response? That could provide some hints as to how to properly fix this.

How to set Allow Parent Paths in IIS Express Config using asp directive

This is a continuation of a answered question in the following link:
How to set Allow Parent Paths in IIS Express Config
I am running a classic asp web site in IISexpress.
The same web site is also used in IIS 7.5 in a w7 pro and works fine enabling the parent paths in the IIS configuration of the web but trying to use the web.config in IISExpress does not work
The problem that I am experiencing is that in the suggested web.config in order to enable the parent paths:
<configuration>
<system.webServer>
<asp
enableParentPaths="true"
bufferingOn="true"
errorsToNTLog="true"
appAllowDebugging="true"
appAllowClientDebug="true"
scriptErrorSentToBrowser="true">
<session allowSessionState="true" />
<cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
<limits />
</asp>
</system.webServer>
</configuration>
I get a 500 error every time that I try to use any asp tag
If I remove the asp tag it all works fine,
Anybody has a clue?
TIA
You have not read carefully. The configuration file that mentioned isn't web.config. It is applicationHost.config. As a shotcut:
Press Win+R
type
notepad "%userprofile%\Documents\IISExpress\config\applicationhost.config"
hit ⏎. This will open the host configuration file with notepad. You need to find your web site's section. It's something like <location path="YourSiteName"> ... </location>. Look inside that node, find the <asp> section and change with yours. Finally, don't forget to remove the asp section from web.config.

Does web.config authorization work on files other than aspx?

I have ASP.NET application with forms authentication. It works well but I have one directory with olly .txt files (no aspx files) that I want users not to access (or only logged in users).
I added web.config to this directory:
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
EDIT:
This works only for .aspx files. It does not work for .txt files and similar. Users cannot browse this directory nor subdirectories however knowing .txt file name they can access it.
I tries IIS6 and IIS 7.5. On IIS6 .txt files are also restricted but on IIS 7.5 not so it may be IIS configuration issue.
Your question depends on the web server you are using. ASP.NET authorization works only with file types that are handled by ASP.NET. If you have IIS 5 or 6, this is normally not true for .txt files or even for .jpg, .gif and pure .html files, but only for aspx, asmx etc.
No problem if you have IIS7 and integrated mode, because ASP.NET is integrated and will be called for every type of file. So if you have IIS5 or 6 you have to register the mime types such as the aspnet.isapi is called for .txt files as well.
UPDATE:
The configuration of
<deny users="*">
locks out all users. It would work only in combination with allow, e.g.
<allow roles="administrators" />
<deny users="*">
like this all users but administrators will be locked out. If a user is authenticated but not adminstrator, he will be redirected to the login page.
The other option is to lock out anonymous users only:
<deny users="?">
Add location section to the web.config with appropriate settings location Element (ASP.NET Settings Schema)
If you use IIS 7+, then you can use the system.webServer/security/authorization http://www.iis.net/ConfigReference/system.webServer/security/authorization section, and have that automatically work for any kind of content in any pipeline mode.
IF you still want to use system.web seciton, then you will need to use Integreated Mode and do the changes that are mentioned in the modules to run for all content, but by far, the simplest is use system.webServer/security/authorization instead.

Deny access to a folder in ASP.NET

is it possible to prevent browsing of a folder contents in an ASP.NET web application other than creating a default page, say using web.config?
I would like to avoid using IIS for this if possible.
Thanks
If you are using IIS7, you can use web.config files for this. Specify a <location> tag for the desired folder, and give it a <directoryBrowse> sub-tag, ie:
<location path="path to your folder">
<system.webServer>
<directoryBrowse enabled="false" />
</system.webServer>
</location>
The previous answer system.webServer -> directoryBrowse is new and can be used when your site is running under IIS7 (be it debugging or otherwise) only, it will not work in IIS6. In IIS6 you need to do it using the IIS management console.

Resources