HttpModule类如下: -
namespace WebApplication1
{
public class RewriterHttpModule : IHttpModule
{
public void Init(HttpApplication r_objApplication)
{
// Register our event handler with Application object.
r_objApplication.BeginRequest += new EventHandler(BeginRequest);
}
public void Dispose()
{
// Left blank because we dont have to do anything.
}
protected void BeginRequest(object r_objSender,
EventArgs r_objEventArgs)
{
// Authenticate user credentials, and find out user roles.
HttpApplication objApp = (HttpApplication)r_objSender;
HttpContext objContext = (HttpContext)objApp.Context;
string fullOrigionalpath = objContext.Request.Url.ToString();
if (fullOrigionalpath.Contains("/Default/Books.aspx"))
{
objContext.RewritePath("/Default.aspx?Category=Books");
}
else if (fullOrigionalpath.Contains("/Default/DVDs.aspx"))
{
objContext.RewritePath("/Default.aspx?Category=DVDs");
}
}
}
}
Web.Config文件如下: -
<configSections>
<section name="rewriter" requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<add name="UrlRewriter" type="WebApplication1.RewriterHttpModule, WebApplication1"/>
</httpModules>
<rewriter>
<rewrite url="~/Default/books.aspx" to="~/Default.aspx?category=books"/>
<rewrite url="~/Default/CDs.aspx" to="~/Default.aspx?category=CDs" />
<rewrite url="~/Default/DVDs.aspx" to="~/Default.aspx?category=DVDs" />
</rewriter>
Sitemaster Page如下: -
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
我的网址重写工作正常但是当在浏览器上加载default.aspx页面时,它没有被css样式表设置样式。可能是什么问题?
答案 0 :(得分:0)
检查此链接:
对于css / javascript,您必须使用绝对路径,例如:
<script src="../my.js"/><script>
将成为
<script src="/js/my.js"/><script>
类似的东西。
忘了解释。
假设在原始链接/default.aspx?Category=books中 你有
当浏览器加载页面时,它将关注/mystyle.css
当您放入/default/books.aspx时(它将加载default.aspx?Category = books) 浏览器将关注/default/mystyle.css(但您在此目录中没有默认目录和mystyle.css。)
答案 1 :(得分:0)
请求脚本文件夹时不执行任何操作:
<if url="^/css/(.+)$">
<rewrite to="~/$1" processing="stop" />
</if>
或者只是将其添加到重写配置
的顶部 <rewrite url="^(/.+(\.gif|\.flv|\.swf|\.png|\.jpg|\.ico|\.pdf|\.doc|\.xls|\.css|\.zip|\.rar|\.js|\.xml|\.mp3)(\?.+)?)$" to="$1" processing="stop" />
答案 2 :(得分:0)
我认为你的css路径会被改变。你有没看过viewsource? 无论如何,以这种方式应用css:
<link href='css/homepage.css' rel='stylesheet' type='text/css' />
希望这有帮助。