English 中文(简体)
日常问题(NET而不是MVC)
原标题:Routing problems (.NET not MVC)

我正在我的网络网站上使用行道。

我想这ur。

前往<代码>http://www.website.com/condos.aspx,然后登上州和地区。

罚款:

routes.MapPageRoute("CondosForRentInArea", "condos/rent/{state}/
{area}", "~/condos.aspx");

但是,我对贾瓦特有一些问题。 因为我可以写:

routes.MapPageRoute("StateAreaJS", "condos/rent/{state}/{area}/scripts/
{filename}.js", "~/scripts/{filename}.js");

我在此发现另一个问题,即:。 Wildcard with ASP.NET MVC MapPageRoute to support organization Legacy Code

但是,我没有在这个网站上使用MVC。 我已尝试这样做:

routes.Add("CondosRentStateAreaJS", new Route("condos/rent/{state}/{area}/scripts/
{filename}.js", new StateAreaJSRouteHandler()));

而且:

public class StateAreaJSRouteHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            string filename = requestContext.RouteData.Values["filename"] as string;

            if (string.IsNullOrEmpty(filename))
            {
                requestContext.HttpContext.Response.Clear();
                requestContext.HttpContext.Response.StatusCode = 404;
                requestContext.HttpContext.Response.End();
            }
            else
            {
                requestContext.HttpContext.Response.Clear();
                requestContext.HttpContext.Response.ContentType = "text/javascript";

                // find physical path to image here.  
                string filepath = requestContext.HttpContext.Server.MapPath("~/scripts/" + filename + ".js");

                requestContext.HttpContext.Response.WriteFile(filepath);
                requestContext.HttpContext.Response.End();
            }
            return null;
        }
    }

Nut 我认为,这部法律是站不住脚的,因为把一个断点放在“档案名称”的线上。

Strangely enough, the CSS is there and the server inserts ../../../ before the folder/filename but the JS is missing.

So how do I correctly get /state/area/scripts/file.js to be just "~/scripts/file.js"?

页: 1 页: 1

你肯定会走在正确的轨道上。 我应该通过编码背后添加文字和风格。 我最后找到了这样一个伟大的解决办法:

HtmlGenericControl validatejs = new HtmlGenericControl("script");
validatejs.Attributes.Add("type", "text/javascript");
    validatejs.Attributes.Add("src", ResolveUrl("~/scripts/validate.js"));
    this.Page.Header.Controls.Add(validatejs);


    HtmlLink fontscss = new HtmlLink();
    fontscss.Href = "~/styles/fonts.css";
    fontscss.Attributes.Add("rel", "stylesheet");
    fontscss.Attributes.Add("type", "text/css");
    this.Page.Header.Controls.Add(fontscss);

我只想补充(对其他神职人员而言),这一方法使我能够去除我的联合和共同支助事务海关,使整个项目更有组织,而且可能更快。

最佳回答

Can you just put the script reference in your master page? That way it will available and make it a lot easier.

问题回答

您也可以按照Ashok的建议,在其使用的网页上提及或使用以下代码。 在前面,用字面字和后面的代码(明显改写姓名):

litJquery.Text = "<script type="text/javascript" src="" + Page.ResolveClientUrl("~/js/jquery-1.6.min.js") + ""></script>";

Good Luck!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签