我无法在Ckeditor中上传图像,因为我的项目是多语言的,并且路由部分无法正常工作。我的网址格式为/language/controller/action
,如果每个网址都没有“语言”部分,我会将其重定向到带有语言元素的网址。
但是在这种情况下,ckeditor url也会重定向。
我想为/ckeditor/Uploadimage
设置一个没有“语言”部分的路由,并且路由可以正常工作而无需重定向。(这是发布请求,重定向后变成get)。
对此我需要帮助。
ckeditor配置文件:
config.filebrowserImageUploadUrl = '/CKEditor/UploadImage';
路由文件:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add("BlogDetails", new SeoFriendlyRoute("{lang}/Home/BlogDetail/{id}",new RouteValueDictionary(new { controller = "Home", action = "BlogDetail" }),new MvcRouteHandler()));
routes.Add("RoomDetails", new SeoFriendlyRoute("{lang}/Home/Room/{id}",new RouteValueDictionary(new { controller = "Home", action = "Room" }),new MvcRouteHandler()));
routes.Add("BlogCategories", new SeoFriendlyRoute("{lang}/Home/Blog/{id}",new RouteValueDictionary(new { controller = "Home", action = "Blog" }),new MvcRouteHandler()));
routes.MapRoute(
name: "DefaultLocalized",
url: "{lang}/{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
用于将重定向网址从非语言重定向到使用语言的网址:
protected void Application_BeginRequest()
{
var routes = RouteTable.Routes;
var httpContext = Request.RequestContext.HttpContext;
if (httpContext == null) return;
var routeData = routes.GetRouteData(httpContext);
var lang = routeData.Values["lang"];
if (lang != null && !string.IsNullOrWhiteSpace(lang.ToString()) && (lang.ToString() == "fa" || lang.ToString() == "en"))
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang.ToString());
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang.ToString());
HttpCookie cooki = new HttpCookie("Language");
cooki.Value = lang.ToString();
cooki.Expires.AddYears(1);
Response.Cookies.Add(cooki);
}
else
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["Language"];
if (cookie != null && cookie.Value != null && (cookie.Value == "fa" || cookie.Value == "en"))
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cookie.Value);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
var ur = string.Format("{0}://{1}{2}{3}{4}",
System.Web.HttpContext.Current.Request.Url.Scheme,
System.Web.HttpContext.Current.Request.Url.Host,
System.Web.HttpContext.Current.Request.Url.Port == 80 ? string.Empty : ":" + System.Web.HttpContext.Current.Request.Url.Port,
"/" + cookie.Value,
System.Web.HttpContext.Current.Request.RawUrl);
Response.RedirectPermanent(ur);
}
else
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fa");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fa");
HttpCookie cook = new HttpCookie("Language");
cook.Value = "fa";
cook.Expires.AddYears(1);
Response.Cookies.Add(cook);
var ur = string.Format("{0}://{1}{2}{3}{4}",
System.Web.HttpContext.Current.Request.Url.Scheme,
System.Web.HttpContext.Current.Request.Url.Host,
System.Web.HttpContext.Current.Request.Url.Port == 80 ? string.Empty : ":" + System.Web.HttpContext.Current.Request.Url.Port,
"/fa",
System.Web.HttpContext.Current.Request.RawUrl);
Response.RedirectPermanent(ur);
}
}
}