Asp.net main website folder - asp.net

I got project that runs on main ftp directory copy all the files to new directory in the ftp with name "new"
And now i have a problem its no reconized the master page in all the aspx files because the path is
~/templ.master
And if i change it to
~/new/templ.master
Its working good but i have a lot of files and codebehind (vb files) too that not reconized
So i ask for a way to change the main website directory on my project
That the project will take all the files from new dir...
How to do it?
Tnx a lot
edit:
again thats my files:
new/templ.Master
new/templ.Master.designer.vb
new/templ.Master.vb
new/default.aspx
in new/templ.Master there is a line like this:
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="templ.master.vb" Inherits="WebApplication1.templ" %>
in new/default.aspx there is a line like this:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/templ.Master" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
when i change in the default.aspx to line:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/new/templ.Master" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
its working but its not read the CodeBehind="templ.master.vb" its take the file templ.master.vb from the root not from the new directory...
and like i said i have a lot of aspx files so i cant change all MasterPageFile="~/templ.Master" to MasterPageFile="~/new/templ.Master" ...
i search a short way to do it...

Set the website directory as main folder of the website and change the default mainpage in web.config as below:
Web.config
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="~/templ.master"/>
</files>
</defaultDocument>
</system.webServer>

try to add this to web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="redirect" stopProcessing="true">
<match url="^$" />
<action type="RedirectToSubdir" url="/new" />
</rule>
</rules>
</rewrite>
</system.webServer>
If it doesn't work, do a manual process: Juts replace "MasterPageFile=" with MasterPageFile="~/new/ by hit CTRl+H in visual studio (select Match case and apply that for current project). Do a same thing for CodeBehind=" etc.

Related

Configure site root URL in ASP.NET MVC

When I print the site root URL in a Razor view like this...
#Url.Content("~/")
... I get the wrong path, e.g.:
/mydomain.org/
How can I change/reconfigure my Web.config so that the path is correct? E.g.
/
The application is installed on a shared hosting in a virtual subdirectory.
<system.web>
<urlMappings enabled="true">
<clear />
<add url="~/" mappedUrl="http://www.example.org" />
</urlMappings>
<system.web>
I am not sure if this works. Maybe something to try though

Registering user controls in cascading web.config files

I have a web.config file in the root folder of my ASP.NET Web Application that registers all user controls in my project.
~/web.config
~/Controls/MyReusableControl.ascx
~/Non/Reusable/Controls/AnotherControl.ascx
~/Non/Reusable/Even/More/Specific/Controls/MyThirdControl.ascx
<system.web>
<pages>
<controls>
<add tagPrefix="uc" tagName="MyReusableControl" src="~/Controls/MyReusableControl.ascx" />
<add tagPrefix="uc" tagName="AnotherControl" src="~/Non/Reusable/Controls/AnotherControl.ascx" />
<add tagPrefix="uc" tagName="MyThirdControl" src="~/Non/Reusable/Even/More/Specific/Controls/MyThirdControl.ascx" />
</controls>
</pages>
</system.web>
Registering every control in the root web.config file seems like a bad idea. Most of my controls are designed specifically for a single page or a group of related pages.
I'd like to register my non-reusable controls in a web.config file that is logically closer to the page where the controls are actually used.
~/Controls/MyControl.ascx
~/web.config
<system.web>
<pages>
<controls>
<add tagPrefix="uc" tagName="MyReusableControl" src="~/Controls/MyReusableControl.ascx" />
</controls>
</pages>
</system.web>
~/Non/Reusable/Controls/AnotherControl.ascx
~/Non/Reusable/web.config
<system.web>
<pages>
<controls>
<add tagPrefix="uc" tagName="AnotherControl" src="~/Non/Reusable/Controls/AnotherControl.ascx" />
</controls>
</pages>
</system.web>
~/Non/Reusable/Even/More/Specific/Controls/MyThirdControl.ascx
~/Non/Reusable/Even/More/Specific/web.config
<system.web>
<pages>
<controls>
<add tagPrefix="uc" tagName="MyThirdControl" src="~/Non/Reusable/Even/More/Specific/Controls/MyThirdControl.ascx" />
</controls>
</pages>
</system.web>
Am I allowed to do that? I tried simply moving the relevant parts of the configuration to the new web.config files, but that seems to break the web forms designer for pages that reference the non-reusable controls.
Element 'AnotherControl' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.
Obviously, my web.config files are all there. What's interesting is that my project does compile and my web pages do show my user controls. It's just Visual Studio designers that crash with the above error.

ASP.NET and System.Web.Optimization not bundling css / js files

I'm trying to use the bundling features of System.Web.Optimization to minify my css and java script.
I have installed the pre release via NuGet
Install-Package Microsoft.Web.Optimization -Pre
and added the following references to my web.config files
/Views/Web.config
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
.....
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
/Web.config
<pages>
<namespaces>
.....
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
I am adding bundles like so
bundles.Add(new StyleBundle("~/Styles").IncludeDirectory("~/Styles", "*.css"));
bundles.Add(new ScriptBundle("~/Scripts/App").IncludeDirectory("~/Scripts/App", "*.js"));
and rendering to my page like this
#Styles.Render("~/Styles")
#Scripts.Render("~/Scripts/App")
Which works great until I turn off debug
<compilation debug="false" targetFramework="4.0" />
The link and script tag added to my page are
<link href="/Styles?v=NMwU-eYeuzJZeywD3xbes6ngUXXJURhda30SEe9mb7Y1" rel="stylesheet">
<script src="/Scripts/App?v=NIL6McOTiWu9OPTVvgMfbmjFtYQhKZDQpRIbKK2kzSk1"></script>
Looking at Chromes network tab I get a 302 redirecting to
/Styles
/Scripts/App
Followed by a 404 :(
I can't seem to get this to work.... has anyone seen a similar issue?
Do you maybe have a conflict with your routing code?
Rick Anderson has a blog post about the bundling / minification features, including a note that you must be careful to avoid routing conflicts. You haven't posted your routing section, but it's something to take a look at.

Caching Profiles web.config vs IIS

What is the difference between configuring a Caching Profile in Web.Config and configuring it in IIS?
If you have this in Web.Config
<caching>
<outputCache enableOutputCache="true" />
<outputCacheSettings>
<outputCacheProfiles>
<add duration="14800" enabled="true" varyByParam="*"
name="AssetCacheProfile" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
And nothing configured in IIS in the Output Caching, will it work?
And what if you add all the extensions I use in Output Caching in IIS, what does that change?
It's a aspx page RetrieveBlob.aspx that uses this Caching Profile:
<%# OutputCache CacheProfile="AssetCacheProfile" %>
<%# Page Language="C#" AutoEventWireup="true" CodeFile="RetrieveBlob.aspx.cs"
Inherits="RetrieveBlob" %>

How do I configure extensionless URLs with the Visual Web Development server?

I'm using Visual Studios' built-in ASP.NET Development Server (VWD) to test my web site during development.
I would like this ASP.NET web site to use extensionless URLs (pages don't require the aspx extension). Ordinarily I would configure a custom 404 in IIS that directs to an ASPX page. How would I do this with VWD?
P.S. This is not an ASP.NET MVC web site.
Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.
(full article here)
Note: this requires IIS7 as it is using the system.webServer section of the web.config.
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
<urlrewritingnet rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--Enable HTM(L) Extensions-->
<add name="pageHTML"
virtualUrl="^~/(.+).htm(.*)"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
<!--Fix the WebResource JS Error-->
<add name="WebResourceFix"
virtualUrl="^~/WebResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/WebResource.axd$1"
ignoreCase="true"/>
<!--Fix the ScriptResource JS Error-->
<add name="ScriptResource"
virtualUrl="^~/ScriptResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/ScriptResource.axd$1"
ignoreCase="true"/>
<!--Allow Extensionless Page Extensions-->
<add name="pageExtensionless"
virtualUrl="^~/(.+)$"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
</rewrites>
</urlrewritingnet>
There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:
http://localhost:2181/Default
<%# Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello World
</div>
</form>
</body>
</html>
If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.
I posted some example code in a previous question.
All you need to do is add the module in two different places within your web.config...
<system.web>
<pages theme="Default" />
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRewriteModule"/>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7

Resources