|
|
Database creation is done in the DBContext after declaring the class. You can tell the DBContext to drop the old database when the Model has changed, or create a new database if there is no database.
You also call an intializer to seed the database with data or images, etc.
So this DBContext will call my initializer:
It will either create a new database, or run a database migration.
public class indigoDBContext : DbContext
{
public indigoDBContext() : base("DefaultConnection")
{
Database.SetInitializer(new indigoIntializer());
}
public DbSet<CRM_ARCHIVES> CRM_ARCHIVES { get; set; }
This is my intializer.
class indigoIntializer : CreateDatabaseIfNotExists<indigoDBContext>
{
protected override void Seed(indigoDBContext context)
{
base.Seed(context);
siteAdministrators.seed(context);
countries.seed(context);
states_Provinces.seed(context);
salesTax.seed(context);
avatars.seed(context);
themes.seed(context);
paymentGateways.seed(context);
paymentBrands.seed(context);
}
}
class Configuration : DbMigrationsConfiguration<indigoDBContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
ContextKey = "Indigo.DataAccessLayer.indigoDBContext";
}
protected override void Seed(Indigo.DataAccessLayer.indigoDBContext context)
{
base.Seed(context);
siteAdministrators.seed(context);
countries.seed(context);
states_Provinces.seed(context);
salesTax.seed(context);
avatars.seed(context);
themes.seed(context);
paymentGateways.seed(context);
paymentBrands.seed(context);
}
}
So when you change the database model, you have to either delete the database and start again or run a migration in package manager (command line) within Visual Studio, migrations add update_today for an example, then migration save .
update_today would be a code function in the DBContext that's sort of like a seed command, in which it uses code to change the database table to the new version.
I prefer to delete the database and start all over again. This ensures that my seed functions work well, the setup programs work when starting from scratch. Then when complete of ready for release, use migration and version control and keep existing data.
All of this runs automatically as soon as you make a DBcontext. The migrations you run manually, unless I can figure out how to run them using npm in the build event.
|
|
|
|
|
|
Google for both terms and do some reading.
|
|
|
|
|
So I'm ready to minify my CSS and Script files. Doing some research for hours, I'm seeing folks are using Gulp and Bower, and not Webgrease. I read the instructions on Bower, but I really don't want to delete by bundles in which I just modified, boostrap, Newtonsoft and everything else and start again.
So I'll try Webgrease first. Questions. What are some of the best practices such as folder structures. I'm using the current folders called Content and Scripts. But in the Webgrease Config XML, there's an input and output folders.
Should I create a new folder for the raw stuff I'm working on, and keep the original folders for the output? Then when I publish the project, the raw folders and output folders copy over? And when I develop, use the output folders.
Or use the same folders, and Webgrease will create a new file adding .min, and then figure out how to use the .min files in production use? I prefer this method, easier to maintain and develop on for me.
Where do you put the webgrease.xml file, in the project root? And then leave the WG.exe in the Visual studio folder, Do I need to map that or something so I call it from my project location?
And this webgrease can run on each project build? Or just call it command line.
In the past, I did this manually, the hard way and spent too much time. Really this is my fist time using any of these tools. Before I write this and start testing, I just wanted to get some feedback on it first. I know they should like dumb questions but not much came back on my searches. Everything was assumed.
Side Rant:
But on a side note or story, I was shopping for brake rotors at R1 Concepts for my car on my phone, and this 1 website consumed 160 megs of my monthly plan within 30 minutes. All the scripts were on the webpage and not separate files, and placed everywhere and not on the bottom. My iphone 6S+ with it's speedy CPU took 5 minutes to load the page compared to my desktop with 6 core Xeon that took 13 seconds. Talk about an example of what not to do.
So this is important to me now, and I would like to automate the task as I continue writing more CSS and JQuery.
modified 6-Jun-16 12:20pm.
|
|
|
|
|
I updated my VS2013 to support Task Runner, Package Intellisense, Grunt Laucher.
Then I updated my project to use Bower, Gulp, Node.js, Git and Npm.
So I'm going to dump the Web Grease, Bundle, and Anti3R? and go this new direction. Dump my optimization, Twitter Boostrap, JQuery, font-awesome NuGet packages then reload the those packages in this new format.
Exactly what I did not want to do. But now I see the benefits of it in the long run.
|
|
|
|
|
Hi All,
i want to show Google map with multiple marked locations with detail on each marked.
Tools: ASP.net web form, C# with ADO.net and SQL sever 2008.
i want to get Latitude and Longitude from database and show marker on google map dynamically.
|
|
|
|
|
As mentioned on your cross-post, this is not an actual question. Asking someone to give you all the code you need is quite rude. Please search google, there are many examples of how to do this. When you get stuck implementing an example then please come back and ask a new question and post the relevant code and where you are stuck.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hello,
I am trying to make an ASP.NET application that uploads a file to a server on a domain.
When I provide my username and password to the application, I can upload but, I need to use credentials who uses the web application that time.
I am using HttpWebRequest object and tried CredentialCache.DefaultCredentials but it didn't work.
Because of security rules in my company, I have to exclude passwords in my app. How do I get NetworkCredentials of the current user?
I couldn't find any solutions? Please help.
Thanks,
Can DOĞU.
|
|
|
|
|
|
My WebConfig file is like this. There is no difference.
Thanks.
|
|
|
|
|
If your code is impersonating the user and the user is authenticated via Windows Authentication then your code is executing as that user.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You should be able get the identity using
HttpContext.Current.User.Identity
|
|
|
|
|
The fact that you need to enter credentials (assuming in a pop-up box) shows that basic authentication is being used. As mentioned you need to use Windows Authentication\Impersonation....it varies depending on your version of IIS. It won't work on all browsers\network configurations though so it's hard to know if you just don't have it configured, or if your particular situation doesn't allow it. Google for more info.
|
|
|
|
|
I wrote a diagnostics program for my web app, Submit a Bug Report.
At the time of submission, I call the page in the controller and grab the HTML with the error, sort of a page snap shot. This way I can see what happened such as a unhanded exception, misspelling or whatever the issue is.
So Now on the resolve program, I want to display that HTML. I'm not if I'm over thinking this or not. I do have the page Url to use, which works. But I thought the page from the actual time it happened would be better.
I tried src=""Data: text/Html, charset: utf-8, the html"" but I get the Url of the page, and not the page. I suspect that the render engine is changing it.
I would just be nice to make it happen. I did get the page to size down correctly, maybe that was the hard part.
<div id="snapShot" class="collapse">
<div class="panel-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
@Html.LabelFor(m => m.Page_HTML, new { @class = "control-label" })
<div class="iframe">
<iframe id="pageSnapShot" class="iframe" src="@Model.Page_HTML"></iframe>
</div>
@Html.ValidationMessageFor(m => m.Page_HTML)
</div>
</div>
</div>
</div>
modified 2-Jun-16 15:29pm.
|
|
|
|
|
If you're using a modern browser[^] - specifically not IE or Edge - you can use the srcdoc attribute[^]:
<iframe id="pageSnapShot" class="iframe" srcdoc="@Model.Page_HTML"></iframe>
For older browsers, either src="data:text/html,@Model.Page_HTML" or src="javascript:'@HttpUtility.JavaScriptStringEncode(Model.Page_Html)'" should work.
Alternatively, this srcdoc polyfill[^] should work in most browsers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'll do some testing on that.
It's for internal use only, and the public will never see it.
Thanks Richard!
|
|
|
|
|
I tried both, same thing. Just got the page URL in the iframe.
I suspect it's a MVC issue.
It's not that important at the moment, so I'll look into it later.
I'll look into how views get rendered into HTML.
|
|
|
|
|
Are you definitely using the right property? In your original message, you were using @Model.Page_URL , but it looks like you want @Model.Page_HTML instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
My bad, In the first post it should of been @Model.Page_HTML
I fix the post to reflect this.
Yes your right, in this post.
I have no clue how MVC was able to take just HTML and figure out what the actual URL for that page is.
|
|
|
|
|
I have the following on my page
<asp:FileUpload ID="flupldDisplayPicture" runat="server" onClick="flupldDisplayPicture_Click"/>
but it will not call the function flupldDisplayPicture_Click? If I change the opening tag to <asp:button ...="" then="" it="" works.
i="" am="" new="" to="" asp="" but="" seasoned="" with="" c#="" and="" trying="" port="" a="" application="" over="" an="" page.
thanks
<pre="" lang="C#">protected void flupldDisplayPicture_Click(object sender, EventArgs e)
{
FileUpload FileUploadControl = new FileUpload();
if (FileUploadControl.HasFile)
{
try
{
if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
{
if (FileUploadControl.PostedFile.ContentLength < 102400)
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
//StatusLabel.Text = "Upload status: File uploaded!";
//imgDisplayPicture.ImageUrl = ("~/") + filename;
imgDisplayPicture.ImageUrl = filename;
}
else
{
//StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
}
}
else
{
//StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
}
}
catch (Exception ex)
{
//StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
|
|
|
|
|
The FileUpload control[^] doesn't have a server-side "click" event. You'll either need to handle the click event for the button that causes the form to submit, or use the Page_Load event and check the IsPostBack property.
Uploading Files in ASP.NET 2.0[^]
Uploading Files (C#) | The ASP.NET Site[^]
You'll probably want to add some checks to make sure the file name ends with an expected extension. It would be quite possible for a hacker to submit a request with a valid "web.config" file, but spoof the content type as "image/jpeg".
You should probably also save the uploaded files in a specific directory, which should be configured as "no-execute" in IIS.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the reply. I have something similar to that and for discussion and testings sake I am now using the code from the first link.
My question is, when I choose a file in the fileupload box, how can I trigger an event? Do I use event handlers like with c# or can I use a worker thread in the background to monitor if fileUpload1.HasFile is true or not?
C#
<%@ Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
FileUpload1.SaveAs("C:\\Uploads\\" +
FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Upload Files</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload File" /> <br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
|
|
|
|
|
You'd have to use client-side code to initiate a post-back. For example:
<asp:FileUpload runat="server" onchange="this.form.submit()" />
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
ProcessFileUpload();
}
}
Background threads almost never make sense in ASP.NET, due to the way it works:
- The browser makes a request to the server;
- The server maps the request to a handler - in this case, you page;
- The server creates an instance of your page to handle the request;
- The page builds its control tree;
- If the request is a "post-back", the page rehydrates the control tree from the saved state sent in the request;
- The page runs through the event handlers, and renders an HTML document;
- The document is sent back to the client, and the page instance is destroyed;
- The client parses and displays the HTML document - this can involve making further requests, running Javascript, etc.
Between the initial request and a "post-back", code running on the server typically has no connection to the client.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Maybe I am going about it the wrong way.
When I use fileupload and have a path for a file inside of the textbox associated with the fileupload control, I want to preview the picture.
Am I going about this the right way?
|
|
|
|