ASP.NET MVC 3.0 Url Routing Issue - asp.net

Hi I have registered route as below :-
routes.MapLocalizedRoute("Category",
"{SeName}-c{categoryId}",
new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional },
new { categoryId = #"\d+", SeName = #"([-\w+]+(/[-\w+]+)*)+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("CategoryWithManufacture",
"{SeName}-d{categoryId}/{ManufactureName}/{Color}",
new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional, Color = UrlParameter.Optional },
new { categoryId = #"\d+", SeName = #"([-\w+]+(/[-\w+]+)*)+", ManufactureName = #"([-\w+]+(/[-\w+]+)*)+", Color = #"([-\w+]+(/[-\w+]+)*)+" },
new[] { "Nop.Web.Controllers" });
We generate these like below :-
href="#Url.RouteUrl("CategoryWithManufacture", new { categoryId = currentCategoryId, SeName = seName, ManufactureName = manufacturerFilterItem.Name, Color = color })"
href="#Url.RouteUrl("Category", new { categoryId = currentCategoryId, SeName = seName})"
There is a way to assign value directly to second parameter "Color" without assign value to "ManufactureName". means :- (Using CategoryWithManufacture Route)
/gloves-d18/red (second parameter)
/gloves-d18/hp/red (first and second both)
I have tried these by making manufactureName & color both optional but when we assign value to first parameter not second it , it work . But we assign value to second parameter not first ,then it is not work .
Please suggest me usable link or sample code.

Only the last parameter can be optional in a route definition. Given the following url /gloves-d18/red the route engine cannot possible know that red refers here to {Color} and not {ManufactureName}. The only to make this work is to write some constraint for those 2 parts. Right now they both have the exactly same regular expression constraint.

Related

How to add conferenceDataVersion to Event using C# using parameters or other way

I am trying to use this but after insert event, the property ConferenceData is null
var pm = new Dictionary<string, string>
{
{"conferenceDataVersion", "1"}
};
calenderEvent.ConferenceData.Parameters = new ConferenceParameters(); calenderEvent.ConferenceData.Parameters.AddOnParameters = new ConferenceParametersAddOnParameters(); calenderEvent.ConferenceData.Parameters.AddOnParameters.Parameters = pm;
You don't need to use the Parameters property in order to set ConferenceDataVersion.
If you just want to add a conference to the Event, you can set the ConferenceDataVersion as a parameter of your request before executing it.
You also have to make sure that the request body has the appropriate conference data properties (requestId, conferenceSolutionKey, etc.).
For example:
Event newEvent = new Event()
{
ConferenceData = new ConferenceData()
{
CreateRequest = new CreateConferenceRequest()
{
ConferenceSolutionKey = new ConferenceSolutionKey()
{
Type = "hangoutsMeet" // Change according to your preferences
},
RequestId = "XXXXX" // Unique request ID
}
},
// ... Rest of event properties (start, end, attendees, name, etc.)
};
EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId);
request.ConferenceDataVersion = 1; // Set conference data version
Event createdEvent = request.Execute();

I want to allow forward slash into SENAME

I want to allow forward slash into SENAME of my nop project. How can i do this using customisation?
for example,
I want product url like "/product/htc-one-m8-android-l-50-lollipop" instead of "/htc-one-m8-android-l-50-lollipop"
I want category url like "/category/desktops" instead of "/desktops"
I am using nopcommerce 4.3 version.
sample code
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("SeName}");
I am not getting call into this TransformAsync method. i want to get call here when i add "/product/sename" into url
public override ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
{
}
You can register routes for Product/ and Category/ path in GenericUrlRouteProvider like:
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("Product/{SeName}");
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("Category/{SeName}");
If you want your existing links to be displayed correctly your also want to update default Product and Category routes and your register routes method should look like:
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
var pattern = "{SeName}";
var productPattern = "Product/{SeName}";
var catgoryPattern = "Category/{SeName}";
if (DataSettingsManager.DatabaseIsInstalled)
{
var localizationSettings = endpointRouteBuilder.ServiceProvider.GetRequiredService<LocalizationSettings>();
if (localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
{
var langservice = endpointRouteBuilder.ServiceProvider.GetRequiredService<ILanguageService>();
var languages = langservice.GetAllLanguages().ToList();
pattern = "{language:lang=" + languages.FirstOrDefault().UniqueSeoCode + "}/{SeName}";
productPattern = "{language:lang=" + languages.FirstOrDefault().UniqueSeoCode + "}/{SeName}";
catgoryPattern = "{language:lang=" + languages.FirstOrDefault().UniqueSeoCode + "}/{SeName}";
}
}
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>(pattern);
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>(productPattern);
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>(catgoryPattern);
//and default one
endpointRouteBuilder.MapControllerRoute(
name: "Default",
pattern: "{controller=Home}/{action=Index}/{id?}");
//generic URLs
endpointRouteBuilder.MapControllerRoute(
name: "GenericUrl",
pattern: "{GenericSeName}",
new { controller = "Common", action = "GenericUrl" });
//define this routes to use in UI views (in case if you want to customize some of them later)
endpointRouteBuilder.MapControllerRoute("Product", productPattern,
new { controller = "Product", action = "ProductDetails" });
endpointRouteBuilder.MapControllerRoute("Category", catgoryPattern,
new { controller = "Catalog", action = "Category" });
endpointRouteBuilder.MapControllerRoute("Manufacturer", pattern,
new { controller = "Catalog", action = "Manufacturer" });
endpointRouteBuilder.MapControllerRoute("Vendor", pattern,
new { controller = "Catalog", action = "Vendor" });
endpointRouteBuilder.MapControllerRoute("NewsItem", pattern,
new { controller = "News", action = "NewsItem" });
endpointRouteBuilder.MapControllerRoute("BlogPost", pattern,
new { controller = "Blog", action = "BlogPost" });
endpointRouteBuilder.MapControllerRoute("Topic", pattern,
new { controller = "Topic", action = "TopicDetails" });
//product tags
endpointRouteBuilder.MapControllerRoute("ProductsByTag", pattern,
new { controller = "Catalog", action = "ProductsByTag" });
}
Update:
In order to allow / in product name, there are multiple changes you need to make.
Allow / in sename, to do that UrlRecordService has GetSeName method and in okChars variable you want to add / as one of the valid characters.
Fix your call related to dynamic routes. You have { missing in your code. It should be:
endpointRouteBuilder.MapDynamicControllerRoute<SlugRouteTransformer>("{SeName}");
Update SlugRouteTransformer's TransformAsync method to unescape URL before searching for matching Url records using:
var urlRecord = _urlRecordService.GetBySlug(Uri.UnescapeDataString(slug));
I believe that is all and after that you should be able to allow / in your entity name. Be aware that this might break existing pages and links might not work perfectly all the time. Also, if you look closely, your product/category url will have %2F in the URL, if you want to change that you will have to unesacpe all the links before rendering, something like:
#Model.Name BUT IT WILL BREAK A LOT OF THINGS!

ASP.NET Entity Framework request SQL

I need to write this SQL statement in Entity Framework:
SELECT
SALARIE.MATRICULE, LIEU, UO, UO_RATTACHEMENT,
PHOTO.PHOTO, SALARIE.NOM, SALARIE.PRENOM
FROM
SALARIE, UNITE_ORG, PHOTO
WHERE
SALARIE.LIEU = UNITE_ORG.UO
I use this method for reading my data :
public JsonResult Read()
{
var nodes = entities.UNITE_ORG.Select(p => new NodeModel { id = p.UO, pid = p.UO_RATTACHEMENT, poste = p.POSTE, img=p.LIB_COMPLET, Fullname=p.RESPONSABLE });
return Json(new { nodes = nodes }, JsonRequestBehavior.AllowGet);
}
I need to change this declaration of nodes.
Thank you
I believe that the equivalent Entity Framework would be the following:
var result = (from s in context.SALARIE
from u in context.UNITE_ORG
from p in context.PHOTO
where s.LIEU == u.UO
select new {
MATRICULE = s.MATRICULE,
LIEU = s.LIEU,
UO = u.UO,
UO_RATTACHEMENT = UO_RATTACHEMENT, // I don't know where this is coming from
PHOTO = p.PHOTO,
NOM = s.NOM,
PRENOM = s.PRENOM
}
);
However, this is just a guess from the information you have giving.
Also, like I have stated in my comment, I really think you should stop using the syntax for cross joins that you are doing (the , seperated syntax)

routing in asp.net mvc gives me lenght

I'm trying to create this route:
http://localhost:28790/Admin/Reporting/Reporting?reportName=MyReportName
In order to access to this Controller:
public ActionResult Reporting(string reportName){...}
For this, i've added this routing in the area:
context.MapRoute(
"Admin_Reporting",
"Admin/Reporting/Reporting/{reportName}",
new
{
reportName = UrlParameter.Optional
}
);
And I've tested this ActionLink
#Html.ActionLink(My Link, "Reporting", "Reporting", new { area = "Admin", reportName = "reportingName" })
But indeed the result is not what I expect to have:
http://localhost:28790/Admin/Reporting/Reporting?Length=9
What can I do in order to have the right URL (first URL of the post) instread of this wrong URL (latest URL of the post) ?
Thanks in advance for your help
You using the wrong overload of #Html.ActionLink(). You need to use this overload when you specify null for the html attributes (the last parameter)
#Html.ActionLink("My Link", "Reporting", "Reporting", new { area = "Admin", reportName = "reportingName" }, null)

ActionResult parameter coming in as null

I have seen a couple related questions to this, but I cannot seem to solve my exact instance. I have a url such as http://127.0.0.1/UTS/Unit/J0000001. That is, my controller is UTS, my action is Unit and there is an optional parameter c_number.
I have my route configured as follows:
routes.MapRoute(
name: "Unit",
url: "{controller}/{action}/{c_number}",
defaults: new { controller = "UTS", action = "Unit", c_number = "" }
);
Then, my action in my controller as:
public ActionResult Unit(string c_number)
{
UnitViewModel uvm = new UnitViewModel();
uvm.unit = pacificRepo.Units.FirstOrDefault(g => g.c_number == c_number);
uvm.geoLocation = pacificRepo.GeoLocations.FirstOrDefault(g => g.geo_location.Latitude == uvm.unit.geo_location.Latitude && g.geo_location.Longitude == uvm.unit.geo_location.Longitude);
return View(uvm);
}
Whenever I go to the example URL I gave above, c_number comes up as null. It should be J0000001. Does anyone see something blatantly obvious that I'm missing?
Since you define it in your Route you don't need to add parameter for your c_number.You can get your value from RouteData dictionary.That c_number parameter has value only if you pass it as QueryString like http://someurl.com/UTS/Unit?c_number="J0000001"
public ActionResult Unit()
{
var cNumber = RouteData.Values["c_number"].ToString();
}

Resources